/*
 * @lc app=leetcode.cn id=1175 lang=javascript
 *
 * [1175] 质数排列
 */

// @lc code=start
/**
 * @param {number} n
 * @return {number}
 */
var numPrimeArrangements = function(n) {
    var table = [2];
    var primecount = 1;
    var n_primecount = 1;
    var product = 1;
    for(var i=3; i<=n; i++){
        var length = table.length;
        for(var j=0; j<length; j++){
            if(i%table[j]==0) break;
        }
        if(j==length){
            table.push(i);
            primecount++;
            product=(product*primecount)%(1e+9+7);
        }else{
            n_primecount++;
            product=(product*n_primecount)%(1e+9+7);
        }
    }
    return product%(1e+9+7);
};
// @lc code=end

